/* Copyright (C) 2010 Fredrique Samuels, fredriquesamuels@gmail.com */

/*
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef TRI_TEXT_H_
#define TRI_TEXT_H_


#include <vector>
#include <string>
#include <string.h>

#include "base/exception.h"
#include "entity.h"
#include "glfont.h"
#include "base/system.h"
#include "base/logging.h"

using namespace std;

namespace tri {

class TText : public tri::TEntity {
public:
	TText();
	virtual ~TText();
	virtual inline void display();
	
	/**
	 * Set the font size
	 */
	void setFontSize(int s);

	/**
	 * Set the character render height
	 */
	void setCharacterHeight(float h);
	float getCharacterHeight();

	/**
	 * Set font
	 */
	void setFont(std::string font);

	void setText(const char* fmt,...);
	void setText(std::string text);
	
	void setTextColor(int r, int g, int b, int a);
	void setTextTargetColor(int r, int g, int b, int a,float t = 1.0);
	
	void setTextBackGroundColor(int r, int g, int b, int a);
	
	std::string getText();
	
	/**
	 * Get the leght of a given text
	 */
	int getDimensions(std::string text,float &width, float &height);
	int getDimensions(float &width, float &height);
	
	//Get the dimensions of the image used to build
	//the given charater
	int getCharBitmapDimensions(char c,int &width, int& height);
	
	void setClipInsets(float inset_left, float inset_top, float inset_right,
					float inset_bottom);
					
	float getGlyphTopMargin();

private:
	void loadFont();
	bool fontExists(std::string font);
	
	void removeFontReference(std::string f);
	std::string getFontFullName();

	int mFontSize;
	float mCharacterHeight;
	std::string mFontName;
	tri::graphics::TColor mTextColor;
	tri::graphics::TColor mTextBGColor;
	
	tri::triFont* mFont;
	bool mReloadFont;
	std::string mText;
	std::string prevFont;
	std::vector<std::string> mLines;
	float mClipInsets[4];
	
	
	static std::map<std::string,tri::triFont*> mFontList;
	static std::map<std::string,int> mFontReferences;
	
	

};

}

#endif
